// pages/mockexam/special/single/detail/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    options: {},
    list: [],
    questionList: [],
    optionList: [],
    listIndex: 0,
    listSize: 0,
    questionIndex: 0,
    qmaxSize: 0,
    qcount: 0,
    submitObj: {},
    flag: true,
    resultInfo: {},
    serverUrl: '',
    analysis: false,
    showImage: true,
    showButton: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    app.paiRequest("/app/mockexam/special/audio/findList", { parentCode: options.parentCode }).then(function (res) {
      var dataList = res.data;
      _this.setData({
        list: dataList,
        listSize: dataList.length,
        options: options
      })
      var oneObj = dataList[0];
      app.paiRequest("/app/mockexam/special/audio/questionList", { 
        specialId: options.parentCode,
        parentCode: oneObj.id 
      }).then(function (ress) {

        var childList = ress.data;
        _this.setData({
          questionList: childList,
          qmaxSize: childList.length,
          qcount: childList.length
        })
        var optionList = _this.data.optionList;
        var option = childList[0];
        app.paiRequest("/app/mockexam/special/audio/optionList", { 
          parentCode: option.id,
          specialId: options.parentCode,
          questionId: option.id
        }).then(function (resss) {
          _this.setData({
            optionList: resss.data
          })
        })
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  nextquestion: function () {
    this.setData({
      questionIndex: this.data.questionIndex + 1
    })
  },
  nextList: function () {
    var _this = this;
    var questionList = this.data.questionList;
    var questionIndex = this.data.questionIndex;
    var obje = questionList[questionIndex + 1];
    var specialId = this.data.options.parentCode;
    if (obje == undefined) {
      var subjectList = this.data.list;
      var subjectIndex = this.data.listIndex;
      if (subjectList[subjectIndex + 1] == undefined) {
        this.setData({
          showButton: true
        })
      } else {
        app.paiRequest("/app/mockexam/special/audio/questionList", {
          specialId: specialId,
          parentCode: subjectList[subjectIndex + 1].id
        }).then(function (res) {
          var questionList = res.data;
          app.paiRequest("/app/mockexam/special/audio/optionList", {
            parentCode: questionList[0].id,
            specialId: specialId,
            questionId: questionList[0].id
          }).then(function (ress) {
            _this.setData({
              questionList: questionList,
              questionIndex: 0,
              listIndex: subjectIndex + 1,
              optionList: ress.data
            })
          })
        })
      }
    } else {
      app.paiRequest("/app/mockexam/special/audio/optionList", {
        parentCode: questionList[questionIndex + 1].id,
        specialId: specialId,
        questionId: questionList[questionIndex + 1].id
      }).then(function (resss) {
        var optionList = resss.data;
        _this.setData({
          optionList: optionList,
          questionIndex: questionIndex + 1
        })
      })
    }
  },
  radioChang: function (e) {
    
  },
  checkChang: function (e) {
    
  },
  submitQuestion: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  // 遮罩层隐藏
  conceal: function () {
    this.setData({ flag: true })
  },

})